import SSEClient from "@/utils/sse";
import { store } from "../utils";
import type { SseTpye } from "../types";

export const useSseClientStore = defineStore({
  id: "pure-sse-client",
  state: (): SseTpye => ({ seeClient: null }),
  actions: {
    connect() {
      this.seeClient = new SSEClient(`/api/sse`);
      this.seeClient.connect();
    },
    disconnect() {
      this.seeClient?.disconnect();
      this.seeClient = null;
    }
  }
});

export function useSseClientStoreHook() {
  return useSseClientStore(store);
}
